From bcf2a11da445fdd71af8eb9eeb5591816571b439 Mon Sep 17 00:00:00 2001 From: Mike Boutin Date: Tue, 4 Aug 2015 18:49:24 -0400 Subject: [PATCH] Change the no_term test to run an external process. Remove $TERM from the new process' environment and verify that output is not sent to stderr. --- src/cargo/core/shell.rs | 4 ++++ tests/test_shell.rs | 22 +++++++++------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/cargo/core/shell.rs b/src/cargo/core/shell.rs index 413c9aa08..6e0a19564 100644 --- a/src/cargo/core/shell.rs +++ b/src/cargo/core/shell.rs @@ -144,6 +144,10 @@ impl MultiShell { impl Shell { pub fn create(out: Box, config: ShellConfig) -> Shell { + // Match from_env() to determine if creation of a TerminfoTerminal is possible regardless + // of the tty status. --color options are parsed after Shell creation so always try to + // create a terminal that supports color output. Fall back to a no-color terminal or write + // output to stderr if a tty is present and color output is not possible. match ::term::terminfo::TermInfo::from_env() { Ok(ti) => { // Color output is possible. diff --git a/tests/test_shell.rs b/tests/test_shell.rs index a91e18c53..a2a5e5638 100644 --- a/tests/test_shell.rs +++ b/tests/test_shell.rs @@ -6,8 +6,9 @@ use hamcrest::{assert_that}; use cargo::core::shell::{Shell, ShellConfig}; use cargo::core::shell::ColorConfig::{Auto,Always, Never}; +use cargo::util::process; -use support::{Tap, shell_writes}; +use support::{Tap, cargo_dir, execs, shell_writes}; fn setup() { } @@ -32,18 +33,6 @@ test!(non_tty { assert_that(&buf[..], shell_writes("Hey Alex\n")); }); -test!(no_term { - let config = ShellConfig { color_config: Always, tty: false }; - let a = Arc::new(Mutex::new(Vec::new())); - - ::std::env::remove_var("TERM"); - Shell::create(Box::new(Sink(a.clone())), config).tap(|shell| { - shell.say("Hey Alex", color::RED).unwrap(); - }); - let buf = a.lock().unwrap().clone(); - assert_that(&buf[..], shell_writes("Hey Alex\n")); -}); - test!(color_explicitly_disabled { let term = TerminfoTerminal::new(Vec::new()); if term.is_none() { return } @@ -90,6 +79,13 @@ test!(color_explicitly_enabled { color::RED).unwrap())); }); +test!(no_term { + // Verify that shell creation is successful when $TERM does not exist. + assert_that(process(&cargo_dir().join("cargo")).unwrap() + .env_remove("TERM"), + execs().with_stderr("")); +}); + fn colored_output(string: &str, color: color::Color) -> io::Result { let mut term = TerminfoTerminal::new(Vec::new()).unwrap(); try!(term.reset()); -- 2.30.2